<!-- 绑定申请 -->
<template>
	<view>
		<view class="block__title">房屋信息</view>

		<view class="cu-form-group arrow" @tap="chooseCommunity">
			<view class="title">小区</view>
			{{communityName}}
		</view>

		<view class="cu-form-group arrow" @tap="chooseBuild">
			<view class="title">楼栋</view>
			<input required readonly label="楼栋" v-model="buildingName" class="text-right" placeholder="请选择楼栋"
				name="buildingName" icon="arrow"></input>
			<text class='cuIcon-right'></text>
		</view>

		<view class="cu-form-group arrow" @tap="chooseUnilt(_selectFloor)">
			<view class="title">单元</view>
			<input required readonly label="单元" v-model="uniltNum" class="text-right" placeholder="请选择单元"
				name="uniltNum" icon="arrow"></input>
			<text class='cuIcon-right'></text>
		</view>

		<view class="cu-form-group arrow" @tap="chooseHouse(_selectUnit)">
			<view class="title">房屋编号</view>
			<input required readonly label="房屋编号" v-model="houseNum" class="text-right" placeholder="请选择房屋"
				name="houseNum" icon="arrow"></input>
			<text class='cuIcon-right'></text>
		</view>


		<view class="cu-form-group">
			<view class="title">房屋户型(室)</view>
			{{houseModelRoom?houseModelRoom:''}}
		</view>
		<view class="cu-form-group">
			<view class="title">房屋户型(厅)</view>
			{{houseModelTing?houseModelTing:''}}
		</view>


		<view class="bottomRegion">
			<button @click="vacantHouse" type="primary">提交申请</button>
		</view>
	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;
	const factory = context.factory;

	export default {
		data() {
			return {
				// plotNum: '', //小区名
				// plotCommunityId: '', //小区id
				communityId: '',
				communityName: '',

				buildingName: '', //楼栋
				buildingNumId: '', //楼栋id

				uniltNum: '', // 单元名
				uniltNumId: '', // 单元id

				houseNum: '', //房屋编号
				houseId: '', //房屋ID

				houseModelRoom: '', //房屋户型(室)
				houseModelTing: '', //房屋户型(厅)

				owerId: '', //业主id
				phone: '',

				_selectFloor: '', //选择的楼栋
				_selectUnit: '', //选择的单元

				floorNum: '',
				unitNum: '',
				roomNum: '',
				housebindstate: 0,
				ownerInfo: {},
				// 用户信息
				userInfo: {},
				// 用户信息
				ownerFlag: false,
				// 是否有业主信息 标记 如果有为 true  没有为false
				roomDetail: {},


				//身份
				identifyState: '', //身份绑定状态
				identIndex: 0,
				ownId: '',
				ownTel: '',
				ownName: '',

			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {

			let userPhone = uni.getStorageSync("userInfo");
			this.phone = userPhone.phone

			// let that = this;

			//加载我的房屋小区
			// that._loadRepairPlots();

			//加载报修类型
			// that._loadRepairTypes();

		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let communityIdTrue = uni.getStorageSync("_selectCommunity");
			this.communityId = communityIdTrue.id
			this.communityName = communityIdTrue.communityName

			let _plotNum = uni.getStorageSync("_selectCommunity");
			let _floorNum = uni.getStorageSync("_selectFloor");
			let _uniltNum = uni.getStorageSync("_selectUnit");
			let _homeNum = uni.getStorageSync("_selectHome");

			// if (_plotNum != null && _plotNum != undefined && _plotNum != '') {
			// 	this.plotNum = _plotNum.communityName + "小区";
			// 	this.plotCommunityId = _plotNum.id; //小区id
			// 	console.log("小区ID", this.plotCommunityId)
			// 	uni.setStorageSync('plotCommunityId', this.plotCommunityId);
			// }
			if (_floorNum != null && _floorNum != undefined && _floorNum != '') {
				this.buildingName = _floorNum.buildingName;
				this.buildingNameId = _floorNum.id; //楼栋id
				console.log("楼栋ID", this.buildingNameId)
				// uni.setStorageSync('buildingNameId', this.buildingNameId);
			}
			if (_uniltNum != null && _uniltNum != undefined && _uniltNum != '') {
				this.uniltNum = _uniltNum.unitName;
				this.uniltNumId = _uniltNum.unitCode; //单元id
				console.log("单元ID", this.uniltNum)
				// uni.setStorageSync('uniltNumId', this.uniltNumId);
			}
			if (_homeNum != null && _homeNum != undefined && _homeNum != '') {
				this.houseNum = _homeNum.houseName;
				this.houseId = _homeNum.id; //房屋id
				this.houseModelRoom = _homeNum.houseModelRoom;
				this.houseModelTing = _homeNum.houseModelTing;
				console.log("房屋ID", this.houseId)
				// uni.setStorageSync('houseNumId', this.houseId);
			}
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {

			// 选择小区
			chooseCommunity: function(e) {
				console.log('点击调用了', e);
				uni.navigateTo({
					url: '/pages/viewCommunitys/viewCommunitys'
				});
			},

			// 选择楼栋
			chooseBuild: function(e) {
				uni.navigateTo({
					url: '/pages/selectFloor/selectFloor'
				});
			},

			// 选择单元
			chooseUnilt(_selectFloor) {
				this._floorNum = uni.getStorageSync("_selectFloor");
				// console.log("_floorNum楼栋数据去选单元",this._floorNum);
				uni.navigateTo({
					// url: '/pages/selectUnit/selectUnit?vUnit=' + _floorNum
					url: '/pages/selectUnit/selectUnit?vUnit=' + JSON.stringify(this._floorNum)
				});
			},
			// 选择房屋
			chooseHouse(_selectUnit) {
				this._unitNum = uni.getStorageSync("_selectUnit");
				uni.navigateTo({
					url: '/pages/selectHouse/selectHouse?vHouse=' + JSON.stringify(this._unitNum)
				});
			},

			// 提交申请
			vacantHouse: function(e) {
				let userId = uni.getStorageSync("commonUser");
				this.userId = userId.id
				this.ownType = userId.proprietorType
				let obj = {
					communityId: this.communityId,
					houseId: this.houseId,
					id: this.userId,
					type: 1,
				}
				uni.request({
					url: constant.url.bindRecords,
					header: context.getHeaders(),
					method: "POST",
					data: obj,
					// data:obj, //动态数据
					success: function(res) {
						console.log("绑定房屋123", res)
						uni.navigateBack({
							url: 'myHouse',
						})
						uni.removeStorageSync("_selectFloor");
						uni.removeStorageSync("_selectUnit");
						uni.removeStorageSync("_selectHome");
						if (res.statusCode == 200 && res.data.code == 0) {
							uni.hideLoading();
							uni.showToast({
								title: "提交成功",
								icon: 'none',
								duration: 2000
							})
						} else if (res.data.code == 500) {
							uni.showToast({
								title: "此房屋已绑定,不能再次绑定",
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: function(e) {
						uni.hideLoading();
						uni.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						})
					}
				});

			},
		}
	};
</script>
<style scoped lang="scss">
	@import "./myHouseDetail.css";

	text {
		text-align: center;
	}

	.block__title {
		margin: 0;
		font-weight: 400;
		font-size: 14px;
		color: rgba(69, 90, 100, .6);
		padding: 40rpx 30rpx 20rpx;
	}

	.bottomRegion {
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		button {
			margin: 15rpx;
			width: 400rpx;
			height: 70rpx;
			border-radius: 40rpx;
			font-size: 26rpx;
			line-height: 70rpx;
		}
	}
</style>
